package com.xiaode.plugin.influx;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.IPlugin;
/**
 * 储存后台操作日志以及用户接口调用记录
 */
public class InFluxDbPlugin implements IPlugin {
	
	public static InfluxDBClient influxDB;
//	public static InfluxDBMapper influxDBMapper;
	private static String influxDbHost;
	private static String influxDborg;
	private static String influxDbtoken;
	private static String influxDbbucket;
	
	
	public InFluxDbPlugin(String configFile) {
		Prop prop = PropKit.use(configFile);
		influxDbHost = prop.get("influxDb2.host");
		influxDborg = prop.get("influxDb2.org");
		influxDbtoken = prop.get("influxDb2.token");
		influxDbbucket = prop.get("influxDb2.bucket");
	}

	@Override
	public boolean start() {
		if(influxDB == null){
			influxDB = InfluxDBClientFactory.create(influxDbHost, influxDbtoken.toCharArray(), influxDborg, influxDbbucket);
		}	
		return true;
	}

	@Override
	public boolean stop() {
		if(influxDB != null){
			influxDB.close();
		}
		return true;
	}

	public static InfluxDBClient getInfluxDB() {
		return influxDB;
	}

	public static void setInfluxDB(InfluxDBClient influxDB) {
		InFluxDbPlugin.influxDB = influxDB;
	}

	public static String getInfluxDbHost() {
		return influxDbHost;
	}

	public static void setInfluxDbHost(String influxDbHost) {
		InFluxDbPlugin.influxDbHost = influxDbHost;
	}

	public static String getInfluxDborg() {
		return influxDborg;
	}

	public static void setInfluxDborg(String influxDborg) {
		InFluxDbPlugin.influxDborg = influxDborg;
	}

	public static String getInfluxDbtoken() {
		return influxDbtoken;
	}

	public static void setInfluxDbtoken(String influxDbtoken) {
		InFluxDbPlugin.influxDbtoken = influxDbtoken;
	}

	public static String getInfluxDbbucket() {
		return influxDbbucket;
	}

	public static void setInfluxDbbucket(String influxDbbucket) {
		InFluxDbPlugin.influxDbbucket = influxDbbucket;
	}

	
	
	

}
